<?php

class View {

    protected $_variables = array();
    protected $_controller;
    protected $_action;

    function __construct($controller, $action) {
        global $session;
		global $twitter;
        global $bitly;

        $this->_controller = $controller;
        $this->_action = $action;
        $this->session = $session;
		
		$this->twitter = $twitter;
		$this->bitly = $bitly;
    }

    function set($name, $value) {
        $this->_variables[$name] = $value;
    }

    function render($render_header = true) {
        extract($this->_variables);

        if ($render_header) {
            if (file_exists(ROOT . DS . 'application' . DS . 'views' . DS . $this->_controller . DS . 'header.php')) {
                include (ROOT . DS . 'application' . DS . 'views' . DS . $this->_controller . DS . 'header.php');
            } else {
                include (ROOT . DS . 'application' . DS . 'views' . DS . 'header.php');
            }
        }

        if (file_exists(ROOT . DS . 'application' . DS . 'views' . DS . $this->_controller . DS . $this->_action . '.php')) {
            include (ROOT . DS . 'application' . DS . 'views' . DS . $this->_controller . DS . $this->_action . '.php');
        }

        if ($render_header) {
            if (file_exists(ROOT . DS . 'application' . DS . 'views' . DS . $this->_controller . DS . 'footer.php')) {
                include (ROOT . DS . 'application' . DS . 'views' . DS . $this->_controller . DS . 'footer.php');
            } else {
                include (ROOT . DS . 'application' . DS . 'views' . DS . 'footer.php');
            }
        }
    }

}
